{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "eeb84a56-59f5-4ef4-80f3-1dc254f242f2",
   "metadata": {},
   "source": [
    "# 第二节、数组的属性"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "ef1dea24-d309-40df-ba30-be3737f5e511",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "05212376-91cb-4823-93ca-33d32f485437",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[[84, 90, 20, 91, 65],\n",
       "        [ 6, 18, 68, 80, 80],\n",
       "        [16, 68,  6, 11, 33],\n",
       "        [ 9,  1, 97, 74, 29]],\n",
       "\n",
       "       [[91,  0,  8, 47, 10],\n",
       "        [14, 93, 91, 67, 78],\n",
       "        [25, 63, 14, 71,  8],\n",
       "        [48, 56,  2, 23, 73]],\n",
       "\n",
       "       [[64, 63, 38, 98, 95],\n",
       "        [70, 99, 15, 61, 16],\n",
       "        [76, 10, 17, 35, 29],\n",
       "        [69, 82, 81, 98, 86]]])"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr = np.random.randint(0, 100, size=(3, 4, 5))\n",
    "arr"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a64fe4de-36a0-4b66-b628-f2873ddb4a79",
   "metadata": {},
   "source": [
    "## 维度"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "4cc1156d-45eb-41a0-ad39-99e1ce156efe",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr.ndim"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a241a141-682c-4b9f-8982-448d05ed7a0c",
   "metadata": {},
   "source": [
    "## 形状"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "0fe9c937-8c47-4fb0-9f2b-c2adc0192a28",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(3, 4, 5)"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6c5b0aae-1e01-4bd9-aca1-c13f31602988",
   "metadata": {},
   "source": [
    "## 元素数量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "cc330b8f-4cc9-4c1e-ab6e-a0795e1eefb0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "60"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr.size"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "725c0cf0-519e-4dd4-be97-b85a64d56a1c",
   "metadata": {},
   "source": [
    "## 数据类型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "3e7cfdfb-8254-49e1-b115-50782ca0ecc9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dtype('int32')"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr.dtype"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "01c3d163-282b-413a-9e42-38b36e902ecd",
   "metadata": {},
   "source": [
    "## 元素大小"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "bde49315-be4e-41ba-ac4e-77b05c64f57d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr.itemsize  # 因为int32是32位，一个字节是8位，所以32/8=4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1322092f-2b8a-4476-8596-572c8457daa1",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
